<template>
   <div>
    <div v-if="mode === 'DESIGN'">
      <el-select class="max-fill" v-if="!expanding" multiple v-model="_value" disabled :placeholder="placeholder" size="default" />
      <el-checkbox-group v-else v-model="_value">
        <el-checkbox class="w-row-text" disabled v-for="(op, index) in options" :key="index" :label="op">{{ op }}</el-checkbox>
      </el-checkbox-group>
    </div>
    <div v-else-if="mode === 'PC' && !readonly">
      <el-select class="max-fill" v-if="!expanding" v-model="_value" multiple clearable :placeholder="placeholder" size="default">
        <el-option v-for="(op, index) in options" :key="index" :value="op" :label="op"></el-option>
      </el-select>
      <el-checkbox-group v-else v-model="_value" size="default">
        <el-checkbox class="w-row-text" style="margin: 5px" v-for="(op, index) in options" :key="index" :label="op">{{ op }}</el-checkbox>
      </el-checkbox-group>
    </div>
    <div v-else-if="mode === 'MOBILE' && !readonly">
      <!--      <div v-if="!expanding">
          <field right-icon="arrow" readonly clickable :value="_value" :placeholder="placeholder" @click="showPicker = true"/>
          <popup v-model:show="showPicker" position="bottom">
            <picker :title="placeholder" show-toolbar :columns="options" @confirm="onConfirm" @cancel="showPicker = false"></picker>
          </popup>
        </div>-->
      <checkbox-group v-model="_value" direction="horizontal" size="default">
        <checkbox style="margin: 5px" :name="op" shape="square" v-for="(op, index) in options" :key="index">{{ op }}</checkbox>
      </checkbox-group>
    </div>
    <div v-else>
      {{ String(_value) }}
    </div>
  </div>
</template>

<script>
import { Checkbox, CheckboxGroup, Picker, Field, Popup } from 'vant'
import componentMinxins from '/@/views/setting/workflow/components/ComponentMinxins'
import { reactive, toRefs, computed } from 'vue'
export default {
    name: 'MultipleSelect',
    mixins: [componentMinxins],
    components: { Checkbox, CheckboxGroup, Picker, Field, Popup },
    props: {
        placeholder: {
            type: String,
            default: '请选择选项',
        },
        modelValue: {
            type: Array,
            default: () => {
                return []
            },
        },
        expanding: {
            type: Boolean,
            default: false,
        },
        options: {
            type: Array,
            default: () => {
                return []
            },
        },
    },
    emits: ['update:modelValue'],
    setup(props) {
        const { modelValue } = toRefs(props)
        const state = reactive({
            showPicker: false,
            checks: [],
        })
        const onConfirm = () => {

        }
        return {
            ...toRefs(state),
            onConfirm
        }
    }
}
</script>

<style lang="scss" scoped>
:deep(.el-checkbox-group) {
  line-height: 10px;
}
</style>